home *** CD-ROM | disk | FTP | other *** search
/ Apple II Magazines (PO) / Nibble Volume 10, No. 12 (1989-12)(MindCraft Publishing)(Side A).zip / Nibble Volume 10, No. 12 (1989-12)(MindCraft Publishing)(Side A).po / FREESPACE.ASM.txt < prev    next >
Text File  |  1996-12-24  |  12KB  |  398 lines

  1. *****************************
  2. * FREESPACE.ASM Source Code *
  3. * by Alan H. Stein          *
  4. * Copyright (c) 1989        *
  5. * MindCraft Publ. Corp.     *
  6. * Concord, MA 01742         *
  7. * Orca/M Assembler          *
  8. *****************************
  9.  
  10.          KEEP        FreeSpace
  11.          MCOPY       FreeSpace.MAC
  12.  
  13. Period   gequ  $FFFF                    ;don't pass "run" code
  14. EventMask gequ $FFFF                    ;handle all events
  15.  
  16. NDA            START
  17.  
  18.          dc    i4'NDA_Open'             ;open the NDA
  19.          dc    i4'NDA_Close'            ;close the NDA
  20.          dc    i4'NDA_Action'           ;perform NDA actions
  21.          dc    i4'NDA_Init'             ;startup/shutdown
  22.          dc    i2'Period'               ;Periodicity of "run" action
  23.          dc    i2'EventMask'            ;permitted events
  24.          dc    C'##'                    ;Name in menu item form
  25.          dc    C'Free Space'            ;Text for NDA name
  26.          dc    C'\H**',i1'0'            ;id field + terminator
  27.  
  28. * Open NDA if not previously open.  Returns ptr to NDA window on the stack,
  29. * just above 3 byte return address.  DM reserves this result space before
  30. * calling NDA_Open w/JSL instruction.
  31.  
  32. NDA_Open ANOP
  33.  
  34. Result   equ   $05                      ;result stack offset after jsl, phb
  35.  
  36.          phb
  37.          phk
  38.          plb                            ;data bank = code bank
  39.  
  40.          lda   NDAActive                ;FreeSpace window already open?
  41.          beq   R1                       ; no, so check drives & open window
  42.          jmp   Ignore                   ; yes, so ignore
  43.  
  44. ****************************************************************
  45. * Get information from disks and save it in memory for use
  46. * with Quickdraw
  47. ****************************************************************
  48.  
  49. R1       ANOP
  50.  
  51.          lda   #49
  52.          sta   WindBot                         ;depth of window
  53.  
  54.          stz   DiskDataOffset                  ;initialize offset to data
  55.          add4  #DiskData,#19,DiskDataAddr      ;store location of disk data
  56.  
  57. * Get information for first device
  58.  
  59.          lda   #dev_name_str
  60.          sta   dev_name
  61.          lda   #dev_name_str|-16
  62.          sta   dev_name+2
  63.          bra   get_vol_info
  64.  
  65. * Get information for next device
  66.  
  67. NextDev  add4  dev_name,#4
  68.          cmp4  #dev_name_end,dev_name          ;down with list of devices?
  69.          bcc   N1                              ;yes
  70.  
  71. get_vol_info volume  vol_list
  72.  
  73.          bcc   SaveIt                          ;volume present -- store info
  74.          cmp   #$11                            ;device present?
  75.          bne   NextDev                         ; yes, so check for next one
  76. N1       jmp   DoneWDevices
  77.  
  78. SaveIt   ANOP
  79.  
  80.          add2  WindBot,#12,WindBot             ;add room for another line
  81.  
  82.          lda   #1
  83.          ldx   DiskDataOffset
  84.          sta   DiskData,x                      ;flag data good
  85.  
  86.          ldx   #VolumeName
  87.          clc
  88.          lda   #DiskData
  89.          adc   DiskDataOffset
  90.          adc   #2                              ;past flag
  91.          tay
  92.          lda   #16                             ;# bytes to transfer (less 1)
  93.          mvn   VolumeName,DiskData             ;transfer data
  94.          add2  DiskDataOffset,#41              ;prepare for next data
  95.  
  96.          div4  total_blocks,#2,capacity        ;divide by 2 to get K
  97.          PH4    capacity
  98.          PH4    DiskDataAddr
  99.          PH2    #11
  100.          PH2    #0
  101.          _long2Dec                             ;store as ASCII string
  102.          add2  DiskDataAddr,#11
  103.  
  104.          div4  free_blocks,#2,free_blocks     ;divide by 2 to get K
  105.          PH4    freeK
  106.          PH4    DiskDataAddr
  107.          PH2    #11
  108.          PH2    #0
  109.          _long2Dec                             ;store as ASCII string
  110.          add2  DiskDataAddr,#30               ;update
  111.  
  112.          jmp         NextDev
  113.  
  114. DoneWDevices         ANOP
  115.          ldx   DiskDataOffset
  116.          stz   DiskData,X               ;flag end of data
  117.  
  118. * Open window
  119.  
  120.          pha                            ;space for result
  121.          pha
  122.          pushptr WindowDef
  123.          _NewWindow                     ;create and open NDA window
  124.  
  125.          plx                            ;pop ptr (low)
  126.          pla                            ;pop ptr (high)
  127.  
  128.          stx   WindowPtr                ;save ptr to window
  129.          sta   WindowPtr+2
  130.  
  131.          sta   Result+2,s               ;save Result on stack (high)
  132.          txa
  133.          sta   Result,s                 ; (low)
  134.  
  135.          PH4 WindowPtr
  136.          _SetSysWindow                  ;mark this as a DA window
  137.  
  138.          lda   #$FFFF
  139.          sta   NDAActive                ;set "open" flag
  140.  
  141.  
  142.          plb
  143.          RTL
  144.  
  145. ****************************************************************
  146. * Close the NDA if not already closed
  147. ****************************************************************
  148.  
  149. NDA_Close ANOP
  150.          phb
  151.          phk
  152.          plb                            ;data bank = code bank
  153.  
  154.          lda   NDAActive                ;FreeSpace window open?
  155.          beq   Ignore                   ; no, so branch
  156.  
  157.          PH4 WindowPtr
  158.          _CloseWindow
  159.  
  160.          stz   NDAActive                ;mark FreeSpace as closed
  161.  
  162. Ignore   plb
  163.          RTL
  164.  
  165. ****************************************************************
  166. * Perform the NDA action
  167. ****************************************************************
  168.  
  169. NDA_Action ANOP
  170.  
  171.          phb                            ;save data bank
  172.          phk
  173.          plb                            ;make data bank = program bank
  174.  
  175.          phy                            ;save incoming data
  176.          phx
  177.          cmp   #1                       ;take action?
  178.          bne   NoAction                 ; no, don't
  179.          jsr   NDA_Event                ; yes, check event
  180.  
  181.  
  182. NoAction ANOP
  183.          lda   #$FFFF                   ;say we took action
  184.  
  185.          plx
  186.          ply                            ;fix stack
  187.  
  188.          plb
  189.          RTL
  190.  
  191.  
  192. * X, Y (pushed on stack) contain ptr to event record
  193.  
  194. NDA_Event ANOP
  195.  
  196. TheEvent equ   $05                      ;1 (base) + 2 (jsr) + 2 (phd)
  197.  
  198.          phd
  199.          tsc
  200.          tcd                            ;align DP w/stack
  201.  
  202.          lda   [TheEvent]               ;get "what" code
  203.  
  204.          cmp   #6                       ;update event?
  205.          bne   te1                      ;not supported
  206.          jsr   DoUpdate
  207.  
  208. TE1      pld                            ;restore DP
  209.          RTS
  210.  
  211. DoUpdate ANOP
  212.          PH4 WindowPtr
  213.          _BeginUpdate                   ;visible region = update region
  214.          jsl   WindUpdate
  215.          PH4 WindowPtr
  216.          _EndUpdate                     ;restore entire visible region
  217.          RTS
  218.  
  219. WindUpdate     ANOP
  220.  
  221. * Make data bank = code bank
  222.  
  223.          phb
  224.          phk
  225.          plb
  226.  
  227. * Get current value of PortRect
  228.  
  229.          pushptr     PortRect
  230.          _getPortRect
  231.  
  232.          lda         #14                ;vertical Position
  233.          sta         Position
  234.          lda         #10                ;horizontal Position
  235.          sta         Position+2
  236.          PH4    Position
  237.  
  238.          _moveTo
  239.          pushptr     Header
  240.          _drawString
  241.  
  242. * Initialize disk data location, offset from start of data
  243.          lda   #(DiskData|-16)
  244.          sta   DiskDataAddr+2
  245.          clc
  246.          lda   #DiskData
  247.          adc   #2
  248.          sta   DiskDataAddr
  249.          stz   DiskDataOffset
  250.  
  251. NextVol  ANOP
  252.  
  253.          ldx   DiskDataOffset
  254.          lda   DiskData,x
  255.          bne   ShowIt                          ;another volume present
  256.          jmp   Done                            ;finished
  257.  
  258. ShowIt   ANOP
  259.  
  260.          clc
  261.          txa
  262.          adc   #41
  263.          sta   DiskDataOffset                  ;prepare offset for next line
  264.  
  265. * Move pen to next Position
  266.  
  267.          add2  Position,#12
  268.          lda   #10
  269.          sta   Position+2
  270.          PH4    Position
  271.          _moveTo
  272.  
  273. * Push address of volume name on stack and print it
  274.  
  275.          PH4    DiskDataAddr
  276.          _drawString
  277.          add2  DiskDataAddr,#17                ;update
  278.  
  279.          lda   #144
  280.          sta   Position+2
  281.          PH4    Position
  282.          _moveTo
  283.  
  284.          PH4    DiskDataAddr
  285.          PH2    #11
  286.          _drawText                             ;total capacity
  287.          PH2    #'K'
  288.          _DrawChar                             ;write K
  289.          add2  DiskDataAddr,#11
  290.  
  291.          lda   #216
  292.          sta   Position+2
  293.          PH4    Position
  294.          _moveTo
  295.  
  296.          PH4    DiskDataAddr
  297.          PH2    #11
  298.          _DrawText
  299.          PH2    #'K'
  300.          _DrawChar
  301.          add2  DiskDataAddr,#13
  302.  
  303.          jmp         NextVol
  304.  
  305. Done     ANOP
  306.  
  307.          plb
  308.          RTL
  309.  
  310. * Startup or shutdown the NDA.  On entry, A = 0 for DeskShutDown,
  311. * A is non-zero for DeskStartup.
  312.  
  313. NDA_Init ANOP
  314.  
  315.          phb
  316.          phk
  317.          plb
  318.  
  319.          cmp   #0                       ;starting up?
  320.          bne   NDA_Init1                ;yes, so do nothing
  321.  
  322.          lda   NDAActive                ;FreeSpace window open?
  323.          beq   NDA_Init1                ;no, so branch
  324.  
  325.          PH4 WindowPtr
  326.          _CloseWindow                   ;close the window
  327.  
  328.          stz   NDAActive                ;set "closed" flag
  329.  
  330. NDA_Init1 plb
  331.           RTL
  332.  
  333. * The data area begins here
  334.  
  335. ****************************************************************
  336. * Window parameters
  337. ****************************************************************
  338.  
  339. WindowDef      ANOP
  340. MainWindow dc  I2'WindEnd-MainWindow'
  341.          dc    I'%1100000010100101'     ;window frame def
  342.          dc    I4'WTitle'               ;pointer to window title
  343.          dc    I4'0'                    ;refcon
  344.          dc    I'0,0,0,0'               ;zoom rectangle
  345.          dc    I4'0'                    ;color table
  346.          dc    I'0,0'                   ;origin offset
  347.          dc    I'250,300'               ;height,width data area
  348.          dc    i'170,300'               ;ht, width max window
  349.          dc    I'0,0'                   ;vert, horiz scroll
  350.          dc    I'0,0'                   ;vert, horiz page
  351.          dc    i4'0'                    ;infor bar refcon
  352.          dc    I2'0'                    ;info bar height
  353.          dc    i4'0'                    ;frame defproc (0=standard)
  354.          dc    i4'0'                    ;infor bar defproc
  355.          dc    I4'WindUpdate'           ;content defproc
  356. WindRect dc    I'28,20,198,320'         ;Content region rectangle
  357.          dc    I4'-1'                   ;At the front
  358.          dc    I4'0'                    ;Storage
  359. WindEnd  ANOP
  360.  
  361. WTitle  DW   ' Free Space Catalog '
  362. WindowPtr ds   4                               ;pointer to window
  363. WindBot  equ   WindRect+4                      ;depth of window
  364.  
  365. NDAActive ds   2                               ;used as a flag
  366.  
  367. PortRect ds    8
  368. Header   DW   'Volume                       Capacity        Free'
  369.  
  370. Position ds    4                               ;coordinates to move to
  371.  
  372. VolumeName     ds    17
  373. DiskDataOffset ds    2
  374. DiskDataAddr   ds    4
  375. DiskData       ds    371
  376.  
  377. vol_list ANOP
  378. dev_name       ds    4                         ;ptr to devise name string
  379. vol_name       dc    i4'VolumeName'            ;ptr to vol name string
  380. total_blocks   ds    4                         ;size in blocks
  381. free_blocks    ds    4                         ;# blocks unused
  382. file_sys_id    ds    2
  383.  
  384. capacity       equ   total_blocks
  385. freeK          equ   free_blocks
  386.  
  387. dev_name_str   DW   '.D1'
  388.                DW   '.D2'
  389.                DW   '.D3'
  390.                DW   '.D4'
  391.                DW   '.D5'
  392.                DW   '.D6'
  393.                DW   '.D7'
  394.                DW   '.D8'
  395. dev_name_end   DW   '.D9'
  396.  
  397.          END
  398.